import React from 'react'
import { changeNav } from '../../../actions'
import { connect } from 'react-redux'
import {
    Button, List, InputItem, Flex, WingBlank, WhiteSpace, Popup, Tag, Toast, Switch
} from 'antd-mobile'
import { createForm } from 'rc-form';
import hhistory from '../../../history'
import { ajaxGet, ajaxPost } from 'wxAjaxUtil';
import styles from '../wxelm/mdConfig.less';

const Item = List.Item;
const Brief = Item.Brief;

class MdConfig extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            isChecked: [],
            mdConfigData: []
        };
        this.submit=this.submit.bind(this);
    }
    componentDidMount() {
        this.props.tochangeNav({
            title: "门店配置", rbtn: [
                <Button key="1" type="primary" onClick={this.submit} inline size="small">确定</Button>
            ]
        });
    }
    //门店配置提交按钮
    submit() {
        var storeConfig=[];
        for (var i = 0; i < this.state.mdConfigData.length; i++) {
            if (this.state.mdConfigData[i].shopId == '') {
                Toast.fail("请输入完整的门店号!",1);
                return;
            }
            storeConfig.push({
                "storeCode": this.state.mdConfigData[i].storeCode,
                "storeName": this.state.mdConfigData[i].storeName,
                "otherInfo": [
                    {
                        "code": "shopId",
                        "label": "餐道门店号",
                        "value": this.state.mdConfigData[i].shopId
                    }
                ]
            })
        }
        var backRouter = this.props.location.state.backRouter;
        hhistory.push({ pathname: backRouter, state: { storeConfig:storeConfig } })
    }

    render() {
        const { wxSubProducts, wxzhctSubProduct, jtData, mdData } = this.props;
        let storeItems = mdData.map((item, index) => {
            this.state.mdConfigData[index]={};
            this.state.mdConfigData[index].storeName = item.name;
            this.state.mdConfigData[index].storeCode = item.code;
            this.state.mdConfigData[index].shopId='';
            return <div>
                <WhiteSpace size='md' styleName="yellow" />
                <List>
                    <Item thumb={item.logo}>
                        {item.name}<Brief>{item.code}</Brief>
                    </Item>
                    <Item><div><span>餐道门店号</span><input onBlur={(e) => { this.state.mdConfigData[index].shopId = e.target.value }} className={styles.input} type="text" placeholder="必填" /></div></Item>
                </List>
            </div >
        });
        return (
            <div>
                {storeItems}
            </div>
        )
    }


}

const mapStateToProps = (state) => ({
    jtData: state.wxSmartdrs.jtData,
    mdData: state.wxSmartdrs.mdData
})
const mapDispatchToProps = (dispatch) => ({
    tochangeNav: navogj => dispatch(changeNav(navogj)),
})

export default connect(mapStateToProps, mapDispatchToProps)(MdConfig)